package com.zpark.cloud.alibaba.controller;

import com.zpark.cloud.alibaba.service.IAccountService;
import com.zpark.cloud.alibaba.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @PackageName: com.zpark.cloud.alibaba.controller
 * @ClassName: AccountController
 * @Description:
 * @author: RZS
 * @date: 2023/6/28  15:08
 */
@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private IAccountService accountService;

    @Value("${spring.application.name}")
    private String serverName;


    @GetMapping("/change/{uid}/{money}")
    public ResponseResult<Void> changeAccountResidue(@PathVariable("uid") Long uid, @PathVariable("money")BigDecimal money){
        // 调用业务层接口
        Integer row = accountService.decreaseResidue(uid, money);
        Integer code = 200;
        String msg = "账户修改成功";

        if (row <= 0) {
            code = 500;
            msg = "账户修改失败";
        }

        return new ResponseResult<>(code, serverName + msg, null);
    }
}
